//
//  WmcCancellationAlertView.swift
//  YPWatermarkCamera
//
//  Created by 马涛 on 2022/6/22.
//

import UIKit
import YPUIKit

// MARK: - [WmcCancellationAlertView]

class WmcCancellationAlertView: WmcBaseView {
    // Lifecycle

    /// 构造方法
    /// - Parameters:
    ///   - integral: 积分
    ///   - content: 提示内容
    ///   - leftActionTitle: leftActionTitle description
    ///   - rightActionTitle: rightActionTitle description
    convenience init(integral: String?,
                     content: String,
                     leftActionTitle: String? = "我在想想",
                     rightActionTitle: String? = "仍要注销")
    {
        self.init(frame: .zero)

        self.rethinkButton.setTitle(leftActionTitle, for: .normal)
        self.cancallation.setTitle(rightActionTitle, for: .normal)

        self.contentLabel.text = content
        guard let inte = integral else { return }
        let attriS = "您的账户还有".yp.makeAttributed { make in
            make.set(font: 15.yp.uiFont(weight: .bold))
                .set(foregroundColor:UIColor.wmc_blackH1_000000)
        }
        let inteAttriS = inte.yp.makeAttributed { make in
            make.set(font: 15.yp.uiFont(weight: .bold))
            make.set(foregroundColor:UIColor.wmc_red_F54A45)
        }
        let subfixAttriS = "积分未使用".yp.makeAttributed { make in
            make.set(font: 15.yp.uiFont(weight: .bold))
                .set(foregroundColor:UIColor.wmc_blackH1_000000)
        }
        attriS.append(inteAttriS)
        attriS.append(subfixAttriS)
        self.titleLabel.attributedText = attriS
    }

    // Internal

    lazy var titleLabel: UILabel = {
        let view = UILabel()
        view.font = 15.yp.uiFont(weight: .bold)
        view.textColor = UIColor.wmc_blackH1_000000
        return view
    }()

    lazy var contentLabel: UILabel = {
        let view = UILabel()
        view.numberOfLines = 0
        view.font = 15.yp.uiFont(weight: .regular)
        view.textColor = UIColor.wmc_grayH7_808080
        return view
    }()

    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.wmc_lineColor
        return view
    }()

    lazy var vLineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.wmc_lineColor
        return view
    }()

    lazy var rethinkButton: UIButton = {
        let view = UIButton()
        view.setTitleColor(UIColor.wmc_grayH7_808080, for: .normal)
        return view
    }()

    lazy var cancallation: UIButton = {
        let view = UIButton()
        view.setTitleColor(UIColor.wmc_grayH7_808080, for: .normal)
        return view
    }()

    override func bindViewAction() {}

    override func makeUI() {
        self.layer.cornerRadius = 4
        self.clipsToBounds = true

        addSubview(titleLabel)
        addSubview(contentLabel)
        addSubview(lineView)
        addSubview(vLineView)
        addSubview(rethinkButton)
        addSubview(cancallation)

        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(32)
            make.left.equalTo(15)
            make.right.equalTo(-15)
        }
        contentLabel.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(9)
            make.left.equalTo(15)
            make.right.equalTo(-15)
        }
        lineView.snp.makeConstraints { make in
            make.top.equalTo(contentLabel.snp.bottom).offset(32)
            make.left.right.equalToSuperview()
            make.height.equalTo(0.5)
        }
        vLineView.snp.makeConstraints { make in
            make.top.equalTo(lineView.snp.bottom)
            make.centerX.equalToSuperview()
            make.width.equalTo(0.5)
            make.height.equalTo(45.wmc_autoVer)
            make.bottom.equalToSuperview()
        }
        rethinkButton.snp.makeConstraints { make in
            make.top.equalTo(lineView.snp.bottom).offset(15)
            make.left.equalToSuperview()
            make.right.equalTo(vLineView.snp.left)
            make.bottom.equalTo(-15)
        }
        cancallation.snp.makeConstraints { make in
            make.top.equalTo(lineView.snp.bottom).offset(15)
            make.left.equalTo(vLineView.snp.right)
            make.right.equalToSuperview()
            make.bottom.equalTo(-15)
        }
    }
}

// MARK: - WmcAlertViewProtocol

extension WmcCancellationAlertView: YPUIPresentTarget {
    /// 显示
    func show() -> Void {
        let config = YPUIPresentController.Config()
        config.contentView = self
        config.transitionAnimated.usingSpringWithDamping = .init(appearDuration: 1, disappearDuration: 1)
        config.transitionAnimated.initialSpringVelocity = .init(appearDuration: 0, disappearDuration: 0)
        config.style = .alert(.Create({ make in
            make.center.equalToSuperview()
            make.left.equalTo(32)
            make.right.equalTo(-32)
        }))
        present(config: config)
    }
}
